<template>
    <div class="good" @click="goDetail">
        <img :src="good.pic" alt="">
        <p>￥{{good.price}}</p>
        <button @click.stop="del(good._id)">删除</button>
    </div>
</template>

<script>
export default {
    props: {
        good: {
            type: Object
        }
    },
    methods:{
        del(id) { 
            this.$emit('remove', id)
        },

        goDetail() {
            this.$router.push({
                path: '/detail',
                query: {
                    item: JSON.stringify(this.good)
                }
            })
        }
    },
}
</script>

<style scoped lang="scss">
.good {
    width: calc((100% - 10px) / 2);
    border: 1px solid #ccc;
    padding: 20px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    p {
        color: #e23033;
    }
    img {
        width: 100%;
    }
    button {
        padding: 6px 0;
    }
}
</style>